//
//  EmptyDataState.swift
//  FrameProduct
//
//  Created by delegate on 2024/2/3.
//

import UIKit

enum EmptyDataState: XYEmptyDataState {
    /// 无数据
    case noDate
    /// 加载中
    case loading
    /// 加载失败
    case failure
    /// 无网络
    case noInternet
    
    var detail: ((UILabel) -> Void)? {
        return { label in
            label.textColor = UIColor.lxs.mainContentColor
            label.font = UIFont.lxs.font(name: .pingFangSCRegular, size: 16.0)
            switch self {
            case .noDate:
                label.text = "暂无数据"
            case .loading:
                label.text = nil
            case .failure:
                label.text = "加载失败，点击重试"
            case .noInternet:
                label.text = "暂无网络"
            }
        }
    }
    var image: ((UIImageView) -> Void)? {
        return {imageView in
            switch self {
            case .noDate:
                imageView.image = nil
            case .loading:
                imageView.image = nil
            case .failure:
                imageView.image = nil
            case .noInternet:
                imageView.image = nil
            }
        }
    }
    var button: ((UIButton) -> Void)? {
        return {
            switch self {
            case .noDate:
                $0.setTitle(nil, for: .normal)
                $0.isHidden = true
            case .loading:
                $0.setTitle(nil, for: .normal)
                $0.isHidden = true
            case .failure:
                $0.setTitle(nil, for: .normal)
                $0.isHidden = true
            case .noInternet:
                $0.setTitle(nil, for: .normal)
                $0.isHidden = true
            }
        }
    }
    
    var customView: UIView? {
        switch self {
        case .loading:
            let indicatorView = UIActivityIndicatorView(style: .gray)
            indicatorView.setContentHuggingPriority(.required, for: .vertical)
            indicatorView.startAnimating()
            return indicatorView
        default:
            return nil
        }
    }
}
